home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 251 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
  2. Message-ID: <9602020959.AA02291@lts.sel.alcatel.de>
  3. X-Original-Date: Fri, 2 Feb 96 10:59:13 +0100
  4. Path: in1.uu.net!bounce-back
  5. Date: 03 Feb 96 04:48:42 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. In-Reply-To: Valentin Bonnard's message of 01 Feb 96 17:10:01 GMT
  8. Newsgroups: comp.std.c++
  9. Subject: Re: Give operator. a chance
  10. References: <3102AD11.1663@et.se> <4e0pj1$rq6@news.bridge.net> <9601260532.14152@mulga.cs.mu.OZ.AU> <4eqr6b$778@s3.iway.fr>
  11. Organization: GABI Software, Sarl.
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMRLpr+EDnX0m9pzZAQF3dAF+PmXFlU7G8vbGJeOrC3FszyFnAYQkWhIo
  14.     3fCDZB69k45JqJ8ceulfUYHmtdAm2MVH
  15.     =+Qvf
  16.  
  17. In article <4eqr6b$778@s3.iway.fr> Valentin Bonnard
  18. <bonnardv@pratique.fr> writes:
  19.  
  20. |> First of all, I suppose there is no difference bewten A + B,
  21. |> A.operator+ (B) and A.plus (B) when operator+ is defined as plus.
  22.  
  23. |> Suppose first you overload operator+, then you overload operator. in
  24. |> MyClass:
  25.  
  26. |> class MyClass {
  27. |> private:
  28. |>    AnnotherClass* theOtherClass;
  29. |> public:
  30. |>    AnnotherClass operator. ();
  31. |>    MyClass       operator+ (int);
  32. |>    void          Something_only_defined_in_MyClass ();
  33. |> };
  34.  
  35. |> MyClass A;
  36.  
  37. |> A + 2; is equivalent with A.operator (2) and (A.operator.).operator (2)
  38.  
  39. No, at least not as I understand the proposal.  A + 2 causes
  40. MyClass::operator+ to be called, with &A as this, and 2 as the
  41. argument.  The operator.() function would only be called when a `.'
  42. appears in the equation.
  43.  
  44. |> You can't even write (&A)->Something_only_defined_in_MyClass () in
  45. |> order to access Something_only_defined_in_MyClass (which is only
  46. |> defined for MyClass): (&A)->a_member is equivalent with
  47. |> ((A.operator.).operator&)->a_member.
  48.  
  49. No, the type of `&A' is MyClass*.  There is no operator.() defined for
  50. this type, nor can there ever be.  There is an operator-> defined, the
  51. built in one.
  52.  
  53. If I write (&A)->, the compiler uses (the built-in) operator&, then
  54. operator-> on the results.  What makes you think it could do anything
  55. else?
  56.  
  57. |> How can yu access Something_only_defined_in_MyClass ?
  58.  
  59. |> If operator. return theOtherClass, why don't you just write:
  60. |> AnnotherClass*    theOtherClass;
  61.  
  62. Because typically, `AnotherClass' is a proxy class (a smart
  63. reference), the user doesn't even know about it, and cannot name it if
  64. he is (since it will be declared private in the container class).
  65.  
  66. --
  67. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  68. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  69. Conseils, itudes et rialisations en logiciel orienti objet --
  70.                 -- A la recherche d'une activiti dans une region francophone
  71. ---
  72. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  73.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  74.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  75.